package com.nimbusung;

import java.io.InputStream;
import java.net.URL;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;

public class ImageFullscreenActivity extends Activity {
	
	private ImageView imageView;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.image_fullscreen_layout);
		
		//Initilize
		imageView = (ImageView) findViewById(R.id.myImageView);
		
		//Get the selected url. 
		String newUrl;
		if (savedInstanceState == null) {
		    Bundle extras = getIntent().getExtras();
		    if(extras == null) {
		        newUrl= null;
		    } else {
		        newUrl= extras.getString("imageUri");
		    }
		} else {
		    newUrl = (String) savedInstanceState.getSerializable("imageUri");
		}
		
		imageView.setImageDrawable(loadImageFromURL(newUrl));
		
		
		
	}
	
	private Drawable loadImageFromURL(String url){
		try{
			InputStream is = (InputStream) new URL(url).getContent();
			Drawable d = Drawable.createFromStream(is, "fileFromUri");
			return d;
		}catch (Exception e) {
			System.out.println(e);
			return null;
		}
	}

}
